#pragma once

#include "Figure.h"
#include <vector>

namespace ACCAD
{
    class Polygon : public IFigure
    {
    public:

        /* Render this figure on the Renderer
         */
        void render(Renderer &renderer, bool picked = false) override;

        /* Save this figure to an output stream
         */ 
        void save(std::ostream &out) override;

        /* Load from an input stream to this figure
         */ 
        void load(std::istream &in) override;

        /* Returns a vertex of the polygon
        */
        Vec2 getAnchor(int id);

        /* Returns the vertices of the polygon
         */
        std::vector<Vec2> getAnchors();

        /* Returns the 8 Points of its border
         * e.g, Right, TopRight, Top, TopLeft, Left, BottomLeft, Bottom, BottomRight 
         */
        std::vector<Vec2> getBorder() override;
        
        /* Returns the <id>-th Point of its border
         */
        Vec2 getBorder(int id) override;

        /* Rescale by dragging the <id>-th border point to <to>
         * Its opposite point should stay still
         */
        void resize(int id, const Vec2 &to) override;

        /* Move an anchor point
         */
        void alter(int id, const Vec2 &to);

        /* Return if a point is inside the ellipse
        */
        bool isInside(const Vec2& point) override;

        /* Returns the TYPE (enum FigureType) of this Figure
         */
        FigureType getType() override;

        /* Deep copy a ellipse;
        */
        Polygon* Clone() override;

        /* [Constructor]
         * Construct a polygon with a list of Vertices
         */
        Polygon(const Color &cborder, const Color &cinner, const std::vector<Vec2> &verts);

        /* [Constructor]
         * Construct a polygon
         */
        Polygon();

        static Vec2 getPos(const std::vector<Vec2> &verts);

    private:

        void reGen();
        
        std::vector<Vec2> vertices;
        float top, bottom, left, right;
    };
}